package com.shujia.source

import org.apache.flink.streaming.api.scala._

object Demo2FileSource {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    /**
      * 2、读取文件 --有界流
      *
      */
    val studentDS: DataStream[String] = env.readTextFile("data/students.txt")

    //取出班级
    val kvDS: DataStream[(String, Int)] = studentDS.map(line => (line.split(",")(4), 1))

    //统计班级的人数
    val clazzNumDS: DataStream[(String, Int)] = kvDS.keyBy(_._1).sum(1)

    clazzNumDS.print()

    env.execute()
  }

}
